package gold.digger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC807 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int maxIncreaseKeepingSkyline(int[][] grid) {
            int n = grid.length;
            int rmax[] = new int[n];
            int cmax[] = new int[n];
            for (int i = 0; i < n; i++) {
                int max = 0;
                for (int j = 0; j < n; j++) max = Math.max(max, grid[i][j]);
                rmax[i] = max;
            }
            for (int j = 0; j < n; j++) {
                int max = 0;
                for (int i = 0; i < n; i++) max = Math.max(max, grid[i][j]);
                cmax[j] = max;
            }
            int ans = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    ans += Math.min(rmax[i], cmax[j]) - grid[i][j];
                }
            }
            return ans;
        }
    }


    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC807 an = new LC807();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
